<template>
  <el-dialog
    class="dialog"
    width="1000px"
    align-center
    :show-close="false"
    v-model="InventoryStore.IsCover.InfoTable"
  >
    <p class="title">
      <span>{{title}}</span>
      <span>
        <el-button type="primary" @click="addOne">{{btnName}}</el-button>
      </span>
    </p>
    <div class="table">
      <TableVue
        :tableData="tableData"
        :tableArr="tableArr"
        :operationObj="operationObj"
        size="large"
        @deleteRow1="goNextZhe"
      ></TableVue>
    </div>
  </el-dialog>
</template>

<script setup>
import { ref } from "vue";
import TableVue from "../../../components/Table.vue";
import { useInventoryStore } from "../../../stores/InventoryVM";
import { getFrmloss, getWatchFrm } from "../../../api/index";
const InventoryStore = useInventoryStore();
defineProps({
  title: {
    type: String,
    default: "商品报损"
  },
  btnName: {
    type: String,
    default: "新增报损"
  }
});
const tableData = ref([]);
getFrmloss(1, 10)
  .then(res => {
    tableData.value = res.data.data.frmlossList;
    tableData.value.forEach((item, index) => {
      if (item.frmlossstatus === "编辑中") {
        tableData.value[index].type1 = "编辑";
      } else {
        tableData.value[index].type1 = "查看";
      }
    });
  })
  .catch(err => {
    console.log(err);
  });

const tableArr = {
  frmlossid: "报损编号",
  time: "报损时间",
  num: "报损数量",
  frmlossstatus: "审核状态"
};
const operationObj = {
  operation1: "报损",
  operation2: "申请送货",
  title1: "操作1", //操作标题
  title2: "操作2",
  type1: "primary", //button 类型
  type2: "primary",
  text1: true, // true 为文字类型
  text2: false,
  bool1: true, //操作是否显示
  bool2: false,
  row: false
};
function addOne() {
  InventoryStore.changeBoolean("BsEditing");
}
function goNextZhe(index) {
  const gnid = tableData.value[index].gnid;
  const frmlossid = tableData.value[index].frmlossid;
  getWatchFrm(gnid, frmlossid)
    .then(res => {
      // console.log(res);

      const tip = tableData.value[index].frmlossstatus;
      if (tip === "编辑中") {
        InventoryStore.changeBoolean("BsEditing");
        InventoryStore.infoArr = res.data.data;
      } else {
        InventoryStore.changeBoolean("BsAudit");
        InventoryStore.infoArr = res.data.data;
      }
    })
    .catch(err => {
      console.log(err);
    });
}
</script>

<style scoped>
.title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 18px;
  font-weight: 200;
  color: black;
  padding-bottom: 20px;
  border-bottom: 1px solid #ccc;
}
.table {
  margin-top: 20px;
}
</style>